package com.wnhz.work.yz.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.base.BaseRVAdapter;
import com.wnhz.work.yz.base.BaseViewHolder;
import com.wnhz.work.yz.bean.ReservedOddBean;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class HistoryOrderActivity extends BaseActivity implements View.OnClickListener {
    private RecyclerView recycler_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history_order);
        getData();
        initTitle();
        initView();
        initData();
    }

    private List<ReservedOddBean.InfoEntity.YusuanListEntity> yuSuan = new ArrayList<>();

    public void getData() {
        yuSuan = (List<ReservedOddBean.InfoEntity.YusuanListEntity>) getIntent().getSerializableExtra("yusuan");

    }

    private void initView() {
        recycler_title = (RecyclerView) findViewById(R.id.recycler_title);
        recycler_title.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    }

    private void initData() {

        recycler_title.setAdapter(new BaseRVAdapter(this, yuSuan) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_history;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {
                holder.setTextView(R.id.title, yuSuan.get(position).getClassname());
                holder.setTextView(R.id.hetong_num,"×"+ yuSuan.get(position).getContract_id());
                holder.setTextView(R.id.project_name, yuSuan.get(position).getProject_name());
                holder.setTextView(R.id.total_desc, "共" + yuSuan.get(position).getTotal_nums() + "件商品 合计￥" + yuSuan.get(position).getTotal_price());
                RecyclerView recycler_content = holder.getView(R.id.recycler_content);
                recycler_content.setLayoutManager(new LinearLayoutManager(HistoryOrderActivity.this, LinearLayoutManager.VERTICAL, false));
                final List<ReservedOddBean.InfoEntity.YusuanListEntity.DataEntity> data = yuSuan.get(position).getData();
                recycler_content.setAdapter(new BaseRVAdapter(HistoryOrderActivity.this, data) {
                    @Override
                    public int getLayoutId(int viewType) {
                        return R.layout.item_recycler_content;
                    }

                    @Override
                    public void onBind(BaseViewHolder holder, int position) {
                        holder.setTextView(R.id.package_name, data.get(position).getPackage_name());
                        holder.setTextView(R.id.package_cate, data.get(position).getPackage_cate());
                        holder.setTextView(R.id.package_money, data.get(position).getPackage_money());
                        holder.setTextView(R.id.package_sku_info, data.get(position).getPackage_sku_info());
                        holder.setTextView(R.id.nums, data.get(position).getNums());
                        x.image().bind(holder.getImageView(R.id.img), data.get(position).getImg());
                    }

                });
            }

        });
    }

    private void initTitle() {
        TextView title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("历史订单");
        findViewById(R.id.btn_main_left).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
        }
    }

}
